package legumes.shared.domain;

import java.io.Serializable;

import javax.persistence.Embedded;
import javax.persistence.Id;


public class OnSaleProduct implements Serializable, Cloneable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id private long id = -1;

	private String comment = "";
	@Embedded private Price price;
	private Product product;

	public long getId() {
		return id;
	}

	
	public void setId(long id_) {
		id = id_;
	}

	public Price getPrice() {
		return price;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	
	
	public void setPrice(Price price) {
		this.price = price;
	}

	@Override
	public boolean equals(Object obj) {
		return getProduct().equals(((OnSaleProduct) obj).getProduct());
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	@Override
	public String toString() {
		return "[OnSaleProduct product=" + getProduct() + " comment="
				+ getComment() + " price=" + getPrice() + "]";
	}

	public static OnSaleProduct newOnSaleProduct(Product p_) {
		OnSaleProduct onSaleProduct = new OnSaleProduct();
		onSaleProduct.setComment("");
		onSaleProduct.setProduct(p_);
		onSaleProduct.setPrice(new Price(1.0f, new Quantity(1f, Unit.KG)));
		return onSaleProduct;
	}

	public OnSaleProduct copy() {
		OnSaleProduct osp = new OnSaleProduct();
		osp.setComment(getComment());
		osp.setPrice(getPrice().clone());
		osp.setProduct(getProduct()); // product is not cloned

		return osp;
	}

}
